package com.hbnu.iostream;

import java.io.IOException;
import java.io.PipedOutputStream;

/**
 * @author kittychen
 * @date 2025-09-30 17:36
 */
public class PipedOutputStreamDemo implements Runnable {

    private PipedOutputStream pipedOutputStream;

    public PipedOutputStreamDemo() {
        this.pipedOutputStream = new PipedOutputStream();
    }

    public PipedOutputStream getPipedOutputStream() {
        return pipedOutputStream;
    }

    @Override
    public void run() {
        String str = "Hello World";
        try {
            pipedOutputStream.write(str.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (pipedOutputStream != null) {
                    pipedOutputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
